#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// 函数声明
void playGame();

int main() {
    char playAgain;
    
    // 初始化随机数种子
    srand(time(NULL));
    
    printf("====================================\n");
    printf("       欢迎来到猜数字游戏！       \n");
    printf("====================================\n");
    
    do {
        playGame();
        
        printf("\n你想再玩一次吗？(y/n): ");
        scanf(" %c", &playAgain);
        
    } while (playAgain == 'y' || playAgain == 'Y');
    
    printf("\n感谢游玩！再见！\n");
    
    return 0;
}

// 游戏主逻辑
void playGame() {
    int secretNumber;
    int guess;
    int attempts = 0;
    
    // 生成1到100之间的随机数
    secretNumber = rand() % 100 + 1;
    
    printf("\n我已经想好了一个1到100之间的数字，开始猜吧！\n");
    
    do {
        printf("请输入你的猜测: ");
        scanf("%d", &guess);
        attempts++;
        
        if (guess < secretNumber) {
            printf("太小了！再试试。\n");
        } else if (guess > secretNumber) {
            printf("太大了！再试试。\n");
        } else {
            printf("恭喜你！猜对了！\n");
            printf("你用了 %d 次猜测。\n", attempts);
            
            // 根据猜测次数给出评价
            if (attempts <= 5) {
                printf("太棒了！你是猜数字高手！\n");
            } else if (attempts <= 10) {
                printf("不错！再接再厉！\n");
            } else {
                printf("继续练习，你会做得更好！\n");
            }
        }
        
    } while (guess != secretNumber);
}